package com.siwei.mes.entity.sync.tc;

import com.siwei.mes.common.validator.MockGroup;
import com.siwei.mes.entity.experiment.Experiment;
import com.siwei.mes.enums.EnturstReasonEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * 砼材-运单(Waybill)实体类
 *
 * @author linzi
 * @since 2024-05-22 21:08:28
 */
@Data
@Accessors(chain = true)
@Table(name = "tc_waybill")
@ApiModel(value = "Waybill", description = "砼材-运单")
public class Waybill implements Serializable {
    private static final long serialVersionUID = -92335949503772806L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "砼材-运单主键ID", name = "id")
    private Long id;
    /**
     * 运单id
     */
    @Column(name = "waybill_id")
    @ApiModelProperty(value = "运单id", name = "waybillId")
    private Long waybillId;
    /**
     * 运单编号
     */
    @Column(name = "waybill_code")
    @ApiModelProperty(value = "运单编号", name = "waybillCode")
    private String waybillCode;
    /**
     * 供货任务id
     */
    @Column(name = "supply_task_id")
    @ApiModelProperty(value = "供货任务id", name = "supplyTaskId")
    @NotNull(groups = MockGroup.class, message = "供货任务id为空")
    private Long supplyTaskId;
    /**
     * 司机姓名
     */
    @Column(name = "driver_name")
    @ApiModelProperty(value = "司机姓名", name = "driverName")
    private String driverName;

    /**
     * 司机电话
     */
    @Column(name = "driver_tel")
    @ApiModelProperty(value = "司机电话", name = "driverTel")
    private String driverTel;
    /**
     * 车号
     */
    @Column(name = "vehicle_num")
    @ApiModelProperty(value = "车号", name = "vehicleNum")
    private String vehicleNum;
    /**
     * 车牌
     */
    @Column(name = "vehicle_plate")
    @ApiModelProperty(value = "车牌", name = "vehiclePlate")
    private String vehiclePlate;
    /**
     * 材料名称
     */
    @Column(name = "project_name")
    @ApiModelProperty(value = "材料名称", name = "projectName")
    private String projectName;
    /**
     * 材料规格
     */
    @Column(name = "project_specs")
    @ApiModelProperty(value = "材料规格", name = "projectSpecs")
    private String projectSpecs;
    /**
     * 产品类型 1水泥 2粉煤灰 3矿渣粉 4粗骨料 5细骨料 6外加剂  7其它
     */
    @Column(name = "project_category")
    @ApiModelProperty(value = "产品类型 1水泥 2粉煤灰 3矿渣粉 4粗骨料 5细骨料 6外加剂  7其它", name = "projectCategory")
    private Integer projectCategory;

    @Column(name = "factory")
    @ApiModelProperty(value = "生产厂家")
    private String factory;
    /**
     * 运输数量(吨)
     */
    @Column(name = "transport_quantity")
    @ApiModelProperty(value = "运输数量(吨)", name = "transportQuantity")
    private BigDecimal transportQuantity;
    /**
     * 签收数量(吨)
     */
    @Column(name = "sign_quantity")
    @ApiModelProperty(value = "签收数量(吨)", name = "signQuantity")
    @NotNull(groups = MockGroup.class, message = "签收数量为空")
    private BigDecimal signQuantity;
    /**
     * 异常数量(吨)
     */
    @Column(name = "abnormal_quantity")
    @ApiModelProperty(value = "异常数量(吨)", name = "abnormalQuantity")
    private BigDecimal abnormalQuantity;
    /**
     * 毛重
     */
    @Column(name = "gross_quantity")
    @ApiModelProperty(value = "毛重", name = "grossQuantity")
    private BigDecimal grossQuantity;
    /**
     * 皮重
     */
    @Column(name = "tare_quantity")
    @ApiModelProperty(value = "皮重", name = "tareQuantity")
    private BigDecimal tareQuantity;
    /**
     * 净重
     */
    @Column(name = "net_quantity")
    @ApiModelProperty(value = "净重", name = "netQuantity")
    private BigDecimal netQuantity;
    /**
     * 运单状态 0作废 1待预约 2待出发 3待到达 4待过磅 5过磅中 6等待卸料 7卸料中 8等待出场 9已完成 10拒收
     */
    @Column(name = "state")
    @ApiModelProperty(value = "运单状态 0作废 1待预约 2待出发 3待到达 4待过磅 5过磅中 6等待卸料 7卸料中 8等待出场 9已完成 10拒收", name = "state")
    @NotNull(groups = MockGroup.class, message = "运单状态为空")
    private Integer state;
    /**
     * 是否有异常 0-没有 1-有
     */
    @Column(name = "has_abnormal")
    @ApiModelProperty(value = "是否有异常 0-没有 1-有", name = "hasAbnormal")
    private Integer hasAbnormal;
    /**
     * 异常信息
     */
    @Column(name = "abnormal_info")
    @ApiModelProperty(value = "异常信息", name = "abnormalInfo")
    private String abnormalInfo;
    /**
     * 是否生成快检实验台帐  0-没有 1-有
     */
    @Column(name = "is_quick")
    @ApiModelProperty(value = "是否生成快检实验台帐  0-没有 1-有", name = "isQuick")
    private Integer isQuick;
    /**
     * 是否生成批检实验台帐 0-没有 1-有
     */
    @Column(name = "is_batch")
    @ApiModelProperty(value = "是否生成批检实验台帐 0-没有 1-有", name = "isBatch")
    private Integer isBatch;
    /**
     * 供货单位
     */
    @Column(name = "supply_company_company")
    @ApiModelProperty(value = "供货单位", name = "supplyCompanyCompany")
    private String supplyCompanyCompany;

    @Column(name = "sync_type")
    @ApiModelProperty(value = "同步数据来源")
    private String syncType;

    @Column(name = "experiment_abnormal_info")
    @ApiModelProperty(value = "生成委托异常信息")
    private String experimentAbnormalInfo;

    @Column(name = "entry_time")
    @ApiModelProperty(value = "进场时间")
    private Date entryTime;


    @Column(name = "gen_quick_quantity")
    @ApiModelProperty(value = "已生成快检委托数量")
    private BigDecimal genQuickQuantity;

    @Column(name = "gen_batch_quantity")
    @ApiModelProperty(value = "已生成批检委托数量")
    private BigDecimal genBatchQuantity;

    @Transient
    @ApiModelProperty(value = "供货单位简称")
    private String supplyCompanyAbbreviation;

    @Transient
    @ApiModelProperty(value = "车号", name = "carnumber")
    private String carnumber;

    @Transient
    @ApiModelProperty(value = "车牌", name = "carLicenseNo")
    private String carLicenseNo;

    @Transient
    @ApiModelProperty(value = "检测类型 1-快检 2-批检")
    private Integer checkType;

    @Transient
    @ApiModelProperty(value = "规格id  pk_materials_spec_config 表的id")
    private Long specId;

    @Transient
    @ApiModelProperty(value = "关键字搜索")
    private String keyword;

    @Transient
    @ApiModelProperty(value = "运单状态名称")
    private String stateName;


    /**
     * 代表数量
     */
    @Transient
    @ApiModelProperty(value = "代表数量", name = "behalfNumber")
    private Double behalfNumber;

    @Transient
    @ApiModelProperty(value = "多条记录集合")
    private List<Long> idList;

    /**
     * 组装试验台账记录
     *
     * @param entity         运单信息
     * @param experimentType 试验类型
     * @return
     */
    public static Experiment payloadExperimentWaybill(Waybill entity, Integer experimentType) {
        Experiment experiment = new Experiment();
        experiment.tcInit(true);
        experiment.setExperimentType(experimentType);
        experiment.setEntrustTime(new Date());
        experiment.setEntrustReasonCode(EnturstReasonEnum.CJ.getCode());
        experiment.setEntrustReasonName(EnturstReasonEnum.CJ.getName());
        return experiment;
    }

    public Waybill init(boolean isCreate) {
        if (isCreate) {
            this.setEntryTime(new Date());
        }
        return this;
    }
}
